package com.kmproject.haifu.mvp.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DataHelper;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.AppConstant;
import com.kmproject.haifu.app.hfinterface.BtnClickCallBack;
import com.kmproject.haifu.app.hfinterface.HousePublishItemClickInterface;
import com.kmproject.haifu.app.hfinterface.HouseReasonRemovalCallBack;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.di.component.DaggerMoreHousePublishRentComponent;
import com.kmproject.haifu.mvp.contract.MoreHousePublishRentContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserBean;
import com.kmproject.haifu.mvp.model.entity.resbean.HouseParmarBean;
import com.kmproject.haifu.mvp.presenter.MoreHousePublishRentPresenter;
import com.kmproject.haifu.mvp.ui.activity.HousePublishSelectTypeActivity;
import com.kmproject.haifu.mvp.ui.activity.HouseRentShowInfoActivity;
import com.kmproject.haifu.mvp.ui.activity.MyStoreActivity;
import com.kmproject.haifu.mvp.ui.adapter.MystoryRenthouseAdapter;
import com.kmproject.haifu.mvp.ui.adapter.NyCollectHouseRentAdapter;
import com.kmproject.haifu.mvp.ui.adapter.PopuWindowSelectPxAdapter;
import com.kmproject.haifu.mvp.ui.holder.AddressSelectHolder;
import com.kmproject.haifu.mvp.ui.holder.PxSelectHolder;
import com.kmproject.haifu.mvp.ui.holder.SxSelectHolderNew;
import com.kmproject.haifu.mvp.ui.holder.ZjSelectHolder;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.yyydjk.library.DropDownMenu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/17/2019 21:49
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class MoreHousePublishRentFragment extends BaseFragment<MoreHousePublishRentPresenter> implements MoreHousePublishRentContract.View {


//    @BindView(R.id.MoreHousePublishRent_RecyclerView)
    RecyclerView MoreHousePublishRentRecyclerView;
//    @BindView(R.id.MoreHousePublishRent_refreshLayout)
    SmartRefreshLayout MoreHousePublishRentRefreshLayout;
    Unbinder unbinder;
//    NyCollectHouseRentAdapter collectHouseRentAdapter;
    @BindView(R.id.mystore_head_typeselect_RadioButton1)
    RadioButton mystoreHeadTypeselectRadioButton1;
    @BindView(R.id.mystore_head_typeselect_RadioButton2)
    RadioButton mystoreHeadTypeselectRadioButton2;
    @BindView(R.id.mystore_head_typeselect_RadioGroup)
    RadioGroup mystoreHeadTypeselectRadioGroup;
    @BindView(R.id.ll_head_type_select_layout)
    LinearLayout llHeadTypeSelectLayout;
    @BindView(R.id.dropDownMenu)
    DropDownMenu dropDownMenu;

//    private int page = 1;
    HouseRentListShowInfoBean houseRentListShowInfoBean;

    //======================================================================筛选相关
    private String headers[] = {"位置", "租金", "筛选", ""};
    private List<View> popupViews = new ArrayList<>();
    private View addressView, zuJinView, shaiXuanViewNew, paiXuView, contentView;
    Map<String, Object> shaiXuanDatas = new HashMap<>();//临时保存筛选条件
//    Map<String, List> shaiXuanDatas = new HashMap<>();//临时保存筛选条件
    private List<HousePayWayBean> addressSelectData, czyqAndfytsSelectData, zjqjHousePayWayBeans, addRessHousePayWayBeansDis;
    private AddressSelectHolder addressSelectHolder;
    private ZjSelectHolder zjSelectHolder;
    private PxSelectHolder pxSelectHolder;
    private SxSelectHolderNew sxSelectHolderNew;
    private HousePayWayBean addressSelectOne;//选择地址，被选中的那一个
    private HousePayWayBean addressSelectFj;//选择附近 和选择地址互斥，
    private String msamllPrice = "", mbigPrice = "";//选择的最小最大价格
    private String pxSelect = "";//排序选中的条件，默认的是空的
    private List<HousePayWayBean> mhousePayWayBeans;//房屋类型，居民住宅、商品房屋
    private List<HousePayWayBean> mhousePayWayBeansXjTsY;//下架提示语
    private MystoryRenthouseAdapter mystoryRenthouseAdapter;
//    private List<HouseRentListShowInfoBean> mhouseRentListShowInfoBeans;
    private HouseParmarBean houseParmarBean = new HouseParmarBean();//查询条件对象
    private LinearLayout mystory_content_lay;
    private View rootView;
    public static MoreHousePublishRentFragment newInstance() {
        MoreHousePublishRentFragment fragment = new MoreHousePublishRentFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerMoreHousePublishRentComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView=inflater.inflate(R.layout.fragment_more_house_publish_rent, container, false);
        return rootView;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        HousePayWayBean housePayWayBean= DataHelper.getDeviceData(getActivity(),AppConstant.user_default_select_area);
        if (housePayWayBean!=null)
        {

            addressSelectOne=housePayWayBean;//默认选中的地址
        }
        initDropDownMenu();
        mPresenter.getHousePayWayBean(Api.DISTANCE, "", addRessHousePayWayBeansDis);//获取筛选条件距离
        mPresenter.getHousePayWayBean(Api.HOUSE_AREA, "", addressSelectData);//获取区域
        mPresenter.getHousePayWayBean(Api.MONTH_RENT, "", zjqjHousePayWayBeans);//租金区间
        mPresenter.dictList(Api.LOWER_SHELF_REASON,"");//获取下架提示语

        ArmsUtils.configRecyclerView(MoreHousePublishRentRecyclerView, new LinearLayoutManager(getActivity()));
        houseRentListShowInfoBean = (HouseRentListShowInfoBean) getActivity().getIntent().getSerializableExtra("HouseRentListShowInfoBean");
        mystoryRenthouseAdapter = new MystoryRenthouseAdapter(new HousePublishItemClickInterface() {
            @Override
            public void callBack(HouseRentListShowInfoBean houseRentListShowInfoBean, HousePayWayBean housePayWayBean, String type) {
                if (type.equals("Obtained"))
                {
                    if (mhousePayWayBeansXjTsY==null)
                    {
                        showMessage("未获取到下架提示语");
                        return;
                    }
                    //下架
                    mPresenter.houseReasonRemoval(getActivity(), llHeadTypeSelectLayout, mhousePayWayBeansXjTsY, new HouseReasonRemovalCallBack() {
                        @Override
                        public void callBack(HousePayWayBean mhousePayWayBean) {
                            if (mhousePayWayBean!=null)
                            {
                                mPresenter.lowerShelfHouseRent(houseRentListShowInfoBean.getRentId(),mhousePayWayBean.getDictId());
                            }
                        }
                    });
                }else if (type.equals("del")){
                    //删除
                    mPresenter.removeHouseRent(houseRentListShowInfoBean.getRentId());
                }
            }
        }, new ArrayList<>(), mhousePayWayBeansXjTsY);
        MoreHousePublishRentRecyclerView.setAdapter(mystoryRenthouseAdapter);
        mystoryRenthouseAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);

        mystoryRenthouseAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                Log.d("onItemChildClick","position"+position);
            }
        });
        mystoryRenthouseAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Log.d("onItemChildClick","position"+position);
            }
        });

        UserBean userBean = DataHelper.getDeviceData(getActivity(), AppConstant.USER_INFO);//获取用户信息
        houseParmarBean.setType("0");//0发布，1收藏
        houseParmarBean.setUserId(userBean.getUserId());
        MoreHousePublishRentRefreshLayout.setEnableRefresh(false);
        MoreHousePublishRentRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                houseParmarBean.setPage((houseParmarBean.getPage()+1));
                mPresenter.listHouseRentCurrentUser(houseParmarBean);
            }
        });

        mPresenter.dictList(Api.HOUSE_CATEGORY, "");//获取类别居民住宅和商业用地
        mystoreHeadTypeselectRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                mystoryRenthouseAdapter.setNewData(null);
                switch (checkedId) {
                    case R.id.mystore_head_typeselect_RadioButton1:
                        if (mhousePayWayBeans == null) {
                            showMessage("未获取到类型");
                            return;
                        }
                        if (mystoryRenthouseAdapter != null) {
                            mystoryRenthouseAdapter.setNewData(null);
                        }

                        houseParmarBean.setPage(1);
                        houseParmarBean.setHouseCategory(mhousePayWayBeans.get(0).getCategory());
                        mPresenter.listHouseRentCurrentUser(houseParmarBean);
                        mPresenter.getQueryConditionTree(mhousePayWayBeans.get(0).getCategory(), "", shaiXuanDatas.containsKey(mhousePayWayBeans.get(0).getCategory()) ? (List<HousePayWayBean>) shaiXuanDatas.get(mhousePayWayBeans.get(0).getCategory()) : null);//获取杀下拉条件

                        break;
                    case R.id.mystore_head_typeselect_RadioButton2:
                        if (mhousePayWayBeans == null) {
                            showMessage("未获取到类型");
                            return;
                        }
                        if (mystoryRenthouseAdapter != null) {
                            mystoryRenthouseAdapter.setNewData(null);
                        }
                        houseParmarBean.setPage(1);
                        houseParmarBean.setHouseCategory(mhousePayWayBeans.get(1).getCategory());
                        mPresenter.listHouseRentCurrentUser(houseParmarBean);
                        mPresenter.getQueryConditionTree(mhousePayWayBeans.get(1).getCategory(), "", shaiXuanDatas.containsKey(mhousePayWayBeans.get(1).getCategory()) ? (List<HousePayWayBean>) shaiXuanDatas.get(mhousePayWayBeans.get(1).getCategory()) : null);//获取杀下拉条件

                        break;
                }

            }
        });

    }

    /**
     * 得到房源类型
     * @return
     */
    public List<HousePayWayBean> getHoustTypes(){
        return mhousePayWayBeans;
    }

    @Override
    public void getQueryConditionTreeSuccess(String houseCategory, List<HousePayWayBean> housePayWayBeans) {
        //筛选条件会员
        shaiXuanDatas.put(houseCategory, housePayWayBeans);
        if (sxSelectHolderNew == null) {
            sxSelectHolderNew = new SxSelectHolderNew(getActivity(), shaiXuanViewNew, new SxSelectHolderNew.selectCallBack() {
                @Override
                public void callBack(HousePayWayBean housePayWayBean) {
                    if (mystoryRenthouseAdapter != null) {
                        mystoryRenthouseAdapter.setNewData(null);
                    }
                    dropDownMenu.closeMenu();
                    //筛选回调
                    mPresenter.listHouseRentCurrentUser(mPresenter.setParmat(houseParmarBean,housePayWayBean));

                }
            });
        }
        sxSelectHolderNew.initShow(getActivity(), new HousePayWayBean("store"), housePayWayBeans);
    }



    /**
     * 初始化弹出控件
     */
    public void initDropDownMenu() {
        dropDownMenu = (DropDownMenu) rootView.findViewById(R.id.dropDownMenu);
        addressView = LayoutInflater.from(getActivity()).inflate(R.layout.popuwindows_seelct_adress, null);
        zuJinView = LayoutInflater.from(getActivity()).inflate(R.layout.popuwindows_seelct_zj, null);
        shaiXuanViewNew = LayoutInflater.from(getActivity()).inflate(R.layout.popuwindows_seelct_sx_new, null);
        paiXuView = LayoutInflater.from(getActivity()).inflate(R.layout.popuwindows_seelct_px, null);
        popupViews.clear();
        popupViews.add(addressView);
        popupViews.add(zuJinView);
        popupViews.add(shaiXuanViewNew);
        popupViews.add(paiXuView);
        contentView = LayoutInflater.from(getActivity()).inflate(R.layout.mystory_content, null);
        View view1 = LayoutInflater.from(getActivity()).inflate(R.layout.mystory_renthouse_lay, null);
        mystory_content_lay = contentView.findViewById(R.id.mystory_content_lay);
        mystory_content_lay.addView(view1);
        MoreHousePublishRentRecyclerView = view1.findViewById(R.id.mystory_renthouse_lay_RecyclerView);
        MoreHousePublishRentRefreshLayout=view1.findViewById(R.id.refreshLayout);

        dropDownMenu.setMenuSelectedImgIcon(R.drawable.houserentingshow_selection_select_tj);
        dropDownMenu.setMenuUnselectedImgIcon(R.drawable.houserentingshow_selection_noselect_tj);
        dropDownMenu.setDropDownMenu(Arrays.asList(headers), popupViews, contentView);
        dropDownMenu.setClickBtn(new DropDownMenu.ClickBtn() {
            @Override
            public void clikCallBack(View view) {
          if (addRessHousePayWayBeansDis==null)
          {
              mPresenter.getHousePayWayBean(Api.DISTANCE, "", addRessHousePayWayBeansDis);//获取筛选条件距离

          }
          if (addressSelectData==null)
          {
              mPresenter.getHousePayWayBean(Api.HOUSE_AREA, "", addressSelectData);//获取区域

          }
          if (zjqjHousePayWayBeans==null)
          {
              mPresenter.getHousePayWayBean(Api.MONTH_RENT, "", zjqjHousePayWayBeans);//租金区间
          }
            }
        });
        initPaiXuPopuwindows();
    }

    /**
     * 初始化排序弹框
     */
    private void initPaiXuPopuwindows() {
        if (pxSelectHolder == null) {
            pxSelectHolder = new PxSelectHolder(getActivity(), paiXuView, new PopuWindowSelectPxAdapter.BtncliickCallBack() {
                @Override
                public void callBack(int index, Object content) {
                    if (mystoryRenthouseAdapter != null) {
                        mystoryRenthouseAdapter.setNewData(null);
                    }

                    pxSelect = (String) content;
                    houseParmarBean.setOrderByFiled(pxSelect);
                    houseParmarBean.setPage(1);
                    mPresenter.listHouseRentCurrentUser(houseParmarBean);
                    dropDownMenu.closeMenu();
                }
            });
        }
    }

    @Override
    public void getMeListSuccess(List<HouseRentListShowInfoBean> houseRentListShowInfoBeans) {
        MoreHousePublishRentRefreshLayout.finishLoadMore();
        if (houseRentListShowInfoBeans == null || houseRentListShowInfoBeans.isEmpty()) {
            MoreHousePublishRentRefreshLayout.setEnableLoadMore(false);
            if (houseParmarBean.getPage() < 2) {
                //第一次请求就是空数据
                if (getActivity().getIntent().getIntExtra("type", 1) == 1) {
                    mystoryRenthouseAdapter.setEmptyView(AppUtil.setEmptyView(getActivity(), "你还没发布租房信息哦！", "快去发布吧~", new BtnClickCallBack() {
                        @Override
                        public void callback(View view) {
                            ArmsUtils.startActivity(HousePublishSelectTypeActivity.class);
                        }
                    }, false));

                } else if (getActivity().getIntent().getIntExtra("type", 1) == 2) {
                    mystoryRenthouseAdapter.setEmptyView(AppUtil.setEmptyView(getActivity(), "你还没收藏哦！", "快去收藏吧~", null, true));

                }
            }
            if (mystoryRenthouseAdapter!=null)
            {
                mystoryRenthouseAdapter.setEmptyView(AppUtil.setEmptyView(getActivity(), "未查询到信息！", "", null, true));

            }
            return;
        }
        if (houseRentListShowInfoBeans.size() < AppConstant.pageSize) {
            //没有下一页了
            MoreHousePublishRentRefreshLayout.setEnableLoadMore(false);
        }else {
            MoreHousePublishRentRefreshLayout.setEnableLoadMore(true);
        }
        if (mystoryRenthouseAdapter.getData()!=null&&!mystoryRenthouseAdapter.getData().isEmpty())
        {
            mystoryRenthouseAdapter.addData(houseRentListShowInfoBeans);
            mystoryRenthouseAdapter.notifyDataSetChanged();
        }else {
            mystoryRenthouseAdapter.setNewData(houseRentListShowInfoBeans);
        }

    }

    /**
     * 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法,
     * 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {@link #setData(Object)}
     * 方法中就可以 {@code switch} 做不同的操作, 这样就可以用统一的入口方法做多个不同的操作, 可以起到分发的作用
     * <p>
     * 调用此方法时请注意调用时 Fragment 的生命周期, 如果调用 {@link #setData(Object)} 方法时 {@link Fragment#onCreate(Bundle)} 还没执行
     * 但在 {@link #setData(Object)} 里却调用了 Presenter 的方法, 是会报空的, 因为 Dagger 注入是在 {@link Fragment#onCreate(Bundle)} 方法中执行的
     * 然后才创建的 Presenter, 如果要做一些初始化操作,可以不必让外部调用 {@link #setData(Object)}, 在 {@link #initData(Bundle)} 中初始化就可以了
     * <p>
     * Example usage:
     * <pre>
     * public void setData(@Nullable Object data) {
     *     if (data != null && data instanceof Message) {
     *         switch (((Message) data).what) {
     *             case 0:
     *                 loadData(((Message) data).arg1);
     *                 break;
     *             case 1:
     *                 refreshUI();
     *                 break;
     *             default:
     *                 //do something
     *                 break;
     *         }
     *     }
     * }
     *
     * // call setData(Object):
     * Message data = new Message();
     * data.what = 0;
     * data.arg1 = 1;
     * fragment.setData(data);
     * </pre>
     *
     * @param data 当不需要参数时 {@code data} 可以为 {@code null}
     */
    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {
        loadingDialog.show();
    }

    @Override
    public void hideLoading() {
        loadingDialog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void getHouseArea(List<HousePayWayBean> housePayWayBeans) {

    }

    @Override
    public void dictListSuccess(List<HousePayWayBean> housePayWayBeans) {
        if (housePayWayBeans==null||housePayWayBeans.isEmpty())
        {
            return;
        }
        switch (housePayWayBeans.get(0).getValue())
        {
            case Api.HOUSE_CATEGORY:
                mhousePayWayBeans = housePayWayBeans;
                if (housePayWayBeans!=null)
                {
                    houseParmarBean.setHouseCategory(housePayWayBeans.get(0).getCategory());
                    mPresenter.getQueryConditionTree(mhousePayWayBeans.get(0).getCategory(),"",shaiXuanDatas.containsKey(mhousePayWayBeans.get(0).getCategory())?(List<HousePayWayBean>) shaiXuanDatas.get(mhousePayWayBeans.get(0).getCategory()):null);//获取杀下拉条件
                    mPresenter.listHouseRentCurrentUser(houseParmarBean);
                }
                break;

            case Api.LOWER_SHELF_REASON:
                //下架提示语
                mhousePayWayBeansXjTsY = housePayWayBeans;
                if (mystoryRenthouseAdapter!=null)
                {

                    mystoryRenthouseAdapter.setMhousePayWayBeans(mhousePayWayBeansXjTsY);
                }

                break;
        }

    }
    @Override
    public void removeHouseRentSuccess() {
        //删除成功刷新数据
        if (mystoryRenthouseAdapter!=null)
        {
            mystoryRenthouseAdapter.setNewData(null);
        }
        houseParmarBean.setPage(1);

        mPresenter.listHouseRentCurrentUser(houseParmarBean);
    }

    @Override
    public void lowerShelfHouseRentSuccess() {
        //下架成功刷新数据
        if (mystoryRenthouseAdapter!=null)
        {
            mystoryRenthouseAdapter.setNewData(null);
        }
        houseParmarBean.setPage(1);
        mPresenter.listHouseRentCurrentUser(houseParmarBean);
    }
    @Override
    public void getHousePayWayBeanSuccess(String value, List<HousePayWayBean> housePayWayBeans) {

        switch (value) {

            case Api.DISTANCE:
                addRessHousePayWayBeansDis=housePayWayBeans;
                break;
            case Api.MONTH_RENT:
                zjqjHousePayWayBeans =housePayWayBeans;
                if (zjSelectHolder == null) {
                    zjSelectHolder = new ZjSelectHolder(getActivity(),housePayWayBeans,zuJinView, new ZjSelectHolder.PriceCallback() {
                        @Override
                        public void callBack(String samllPrice, String bigPrice) {
                            msamllPrice = samllPrice;
                            mbigPrice = bigPrice;
                            houseParmarBean.setPage(1);
                            if (TextUtils.isEmpty(samllPrice))
                            {
                                houseParmarBean.setMinMonthRent(null);
                            }else {
                                houseParmarBean.setMinMonthRent(samllPrice);
                            }
                            if (TextUtils.isEmpty(bigPrice))
                            {
                                houseParmarBean.setMaxMonthRent(null);
                            }else {
                                houseParmarBean.setMaxMonthRent(mbigPrice);
                            }
                            if (mystoryRenthouseAdapter!=null)
                            {
                                mystoryRenthouseAdapter.setNewData(null);
                            }
                            mPresenter.listHouseRentCurrentUser(houseParmarBean);
                            dropDownMenu.closeMenu();
                        }
                    });
                }
                break;
            case Api.HOUSE_AREA:
                this.addressSelectData = housePayWayBeans;
                if (addressSelectHolder == null && housePayWayBeans != null && !housePayWayBeans.isEmpty()&&addRessHousePayWayBeansDis!=null) {
                    addRessHousePayWayBeansDis.add(0,new HousePayWayBean("不限"));
                    //请求到地址后默认加载数据

                    addressSelectHolder = new AddressSelectHolder(getActivity(), addressView, housePayWayBeans,addRessHousePayWayBeansDis,addressSelectOne);
                    addressSelectHolder.init(new AddressSelectHolder.SelectAddressCallBack() {
                        @Override
                        public void callBack(String type, int index, Object o) {
                            if (index==0)
                            {
                                dropDownMenu.setTabText("不限");
                                houseParmarBean.setDis(null);
                                houseParmarBean.setHouseArea(null);
                                houseParmarBean.setLgt(null);
                                houseParmarBean.setLat(null);
                                houseParmarBean.setPage(1);
                                mPresenter.listHouseRentCurrentUser(houseParmarBean);
                                dropDownMenu.closeMenu();
                                return;
                            }
                            if (type.equals("区域")) {
                                addressSelectOne = (HousePayWayBean) o;
                                addressSelectFj = null;
                                dropDownMenu.setTabText(type.equals("区域") ? ((HousePayWayBean) o).getName() : type);
                                houseParmarBean.setDis(null);
                                houseParmarBean.setHouseArea(addressSelectOne.getDictId());
                                houseParmarBean.setLgt(null);
                                houseParmarBean.setLat(null);

                            } else {
                                dropDownMenu.setTabText(type.equals("区域") ? ((HousePayWayBean) o).getName() : type);
                                addressSelectOne = null;
                                addressSelectFj = (HousePayWayBean) o;
                                if (!addressSelectFj.getName().equals("不限"))
                                {
                                    houseParmarBean.setDis(addressSelectFj.getCategory());
                                }else {
                                    houseParmarBean.setDis(null);
                                }
                                houseParmarBean.setHouseArea(null);
                                Location location=startLocation();
                                if (location!=null)
                                {
                                    houseParmarBean.setLgt(String.valueOf(location.getLongitude()));
                                    houseParmarBean.setLat(String.valueOf(location.getLatitude()));

                                }else {
                                    showMessage("未获取到经纬度信息");
                                }
                                //必须设置经纬度
                            }
                            mPresenter.listHouseRentCurrentUser(houseParmarBean);
                            dropDownMenu.closeMenu();
                        }
                    });
                }
                break;
        }
    }
    /**
     * 开始定位
     * @return
     */
    public Location startLocation() {
        LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        // Criteria是一组筛选条件
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        //设置定位精准度
        criteria.setAltitudeRequired(false);////设置是否可以定位海拔,如果设置定位海拔，返回一定是gps
        //是否要求海拔
        criteria.setBearingRequired(true);
        //是否要求方向
        criteria.setCostAllowed(true);
        //是否要求收费
        criteria.setSpeedRequired(true);
        //是否要求速度
        criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
        //设置电池耗电要求
        criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
        //设置方向精确度
        criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);
        //设置速度精确度
        criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
        //设置水平方向精确度
        criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
        //设置垂直方向精确度
        Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
        return location;
    }
}
